<?php
namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller
{
    public function _initialize() {
        $this->theme(C('NOW_THEME'));
        $this->assign('theme', C('NOW_THEME'));
    }

    public function morecount(){
        $pageSize = 11;
        $page = $_POST['page'] ? to_int(I("post.page")) : 1;
        $pageB = ($page - 1) * $pageSize;
        $agent_id = session("user_id");
        $status = (I('post.status'));

        $beginYesterday = begin_Yesterday();
        $endYesterday = end_Yesterday();
        $beginThismonth = begin_This_month();
        $endThismonth = end_This_month();
        if($status == "t"){
            // 本月消费
            $where_a['time'] = array(array('gt',$beginThismonth),array('lt',$endThismonth)) ;
            $where_a['status'] = 3;
            $where_a['uid'] = $agent_id;
            $reg = M('order')->where($where_a)->order('time DESC')->limit($pageB, $pageSize)->select();
        }else if($status == "s"){
            // 昨日消费
            $where_c['uid'] = $agent_id;
            $where_c['status'] = 3;
            $reg = M('order')->where($where_c)->order('time DESC')->limit($pageB, $pageSize)->select();
        }else if($status == "a"){
            // 利润
            $where_b['re_agent'] = $agent_id;
            $where_b['r_time'] = array(array('gt',$beginThismonth),array('lt',$endThismonth));
            $where_b['r_status'] = 1;
            $reg = M('rebate')->where($where_b)->order('r_time DESC')->limit($pageB, $pageSize)->select();
        }
        if(!$reg) {
        echo 1;
        }else{
            $this->assign("reg",$reg);
            $this->display();
        }
    }

    public function index()
    {
        // url中用来跨页面传参的shop_id
        $shop_id = trim(I('get.shop_id'));
        $les = M("shop")->where(array("id"=>$shop_id))->find();
        if(!$shop_id || !$les){
            exit("该店铺不存在");
        }
        session('url_shop_id', $shop_id);
        //自定义页面
        $diy_mods = M("temp_diy")->where("shop_id = %d and page_code = 'index'" ,array($shop_id))
            ->order("temp_sort asc")->select();
        $htmls = D("TempDiy")->decode_html( $diy_mods );
        $this->assign("htmls", $htmls);
        $this->assign('shop_id', $shop_id);
        $this->display();
    }
}